<template>
  <div>
    <h1 style="margin-top: 10%;margin-left: 0%;">南京童心门诊后台管理系统</h1>
    <div class="login-box" id="app">

      <el-row>
        <el-col :span="8" >
          <el-input id="name" v-model="userName" placeholder="请输入帐号">
            <template slot="prepend">帐号</template>
          </el-input>
        </el-col>
        <div style="height: 50px;"></div>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-input id="password" v-model="password" type="password" placeholder="请输入密码" @keyup.enter.native="check">
            <template slot="prepend">密码</template>
          </el-input>
        </el-col>
        <div style="height: 50px;"></div>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-button id="login" v-on:click="check" style="width:100%" type="primary">登录</el-button>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
  export default {
    name: "login",
    data() {
      return {
        userName: '',
        password: '',
        result: ''
      }

    },
    methods: {
      check() {
        // alert(this.userName);
        if(this.userName===''||this.password==''){
          this.$message({
            showClose: true,
            message: '账号密码不能为空',
            type: 'warning'
          });
        }
        this.$ajax.get('http://47.75.110.31:8080/dcinfo/findByPhonenumber?phonenumber='+this.userName)
          .then(response => {
            this.userinfo = response.data;
            if (this.userinfo[0].sex===this.password){
              if(this.userinfo[0].sex=='admin'){
                this.$router.push('/Admininfo');
                this.$message({
                  message: '恭喜登录成功'+this.userName,
                  type: 'success'
                });
              }else {
                this.$router.push('/Dcinfo');
                localStorage.setItem('User', this.userinfo[0].name)
                this.$message({
                  message: '恭喜登录成功'+this.userName,
                  type: 'success'
                });
              }
            } else {
              this.$message({
                message: '密码错误',
              });
            }
        })
      }
    }
  }
</script>

<style scoped>
  /*.el-row {*/
  /*margin-bottom: 20px;*/

  /*&*/
  /*:last-child {*/
  /*margin-bottom: 0;*/
  /*}*/

  /*}*/
  .login-box {
    margin-top: 10%;
    margin-left: 40%;
  }
</style>
